package com.itheima.redbaby.activity;


import com.itheima.redbaby.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class PayWayActivity extends Activity implements OnClickListener{
	private RelativeLayout pay_cash_rel;
	private RelativeLayout pay_poss_rel;
	private RelativeLayout pay_zhifubao_rel;
	private int type=3;//支付方式  默认是支付宝支付
	private ImageView pay_cash_img;
	private ImageView pay_poss_img;
	private ImageView pay_zhifubao_img;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pay_way_activity);
		init();//初始化界面
	}
	private void init() {
		pay_cash_rel = (RelativeLayout) findViewById(R.id.pay_cash_rel);
		pay_cash_rel.setOnClickListener(this);
		
		pay_poss_rel = (RelativeLayout) findViewById(R.id.pay_poss_rel);
		pay_poss_rel.setOnClickListener(this);
		
		pay_zhifubao_rel = (RelativeLayout) findViewById(R.id.pay_zhifubao_rel);
		pay_zhifubao_rel.setOnClickListener(this);
		
		//图片信息 点击显示
		pay_cash_img = (ImageView) findViewById(R.id.pay_cash_img);
		pay_poss_img = (ImageView) findViewById(R.id.pay_poss_img);
		pay_zhifubao_img = (ImageView) findViewById(R.id.pay_zhifubao_img);
	}
	
	@Override
	public void onClick(View v) {
		Intent data=new Intent();
		switch (v.getId()) {
		case R.id.pay_cash_rel:
			System.out.println("现金支付");
			type=1;
			showPic(pay_cash_img);
			hidePic(pay_poss_img);
			hidePic(pay_zhifubao_img);
			
			data.putExtra("type", type);
			setResult(Activity.RESULT_OK, data);
			finish();
			break;
		case R.id.pay_poss_rel:
			System.out.println("到付——POSS");
			type=2;
			showPic(pay_poss_img);
			hidePic(pay_cash_img);
			hidePic(pay_zhifubao_img);
			data.putExtra("type", type);
			setResult(Activity.RESULT_OK, data);
			finish();
			break;
		case R.id.pay_zhifubao_rel:
			System.out.println("支付宝");
			type=3;
			showPic(pay_zhifubao_img);
			hidePic(pay_poss_img);
			hidePic(pay_cash_img);
			data.putExtra("type", type);
			setResult(Activity.RESULT_OK, data);
			finish();
			break;
		}
	}
	
	
		@Override
		public void onBackPressed() {
			Intent data=new Intent();
			data.putExtra("type", type);
			setResult(Activity.RESULT_OK, data);
			finish();
		}
		private void showPic(ImageView img) {
			img.setVisibility(View.VISIBLE);
		}
		//隐藏图片
		private void hidePic(ImageView img) {
			img.setVisibility(View.GONE);
		}
	
}
